
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title> 地理信息编辑 </title>
    <link rel="stylesheet" type="text/css" href="/css/style.css" />

    <style type="text/css">
        *, body {
            margin: 0px;
            font-family: '微软雅黑';
        }
    </style>
    <script src="/js/jquery-1.10.2.min.js"></script>
    <script src="/js/jquery.form.js"></script>
    <script src="/js/generic.js"></script>
</head>

<body>
<table class="maintable">
    <tr>
        <td class="rightmaintd" valign="top">
            <div class="searchdiv">
                <a href="/dlxx">&lt; 返回</a>
                <div class="rightsearchdiv"><!-- name --></div>
            </div>
            <table class="leftrighttable" border="0">
                <tr>
                    <td class="lefttdtable" width="50%" valign="top">
                        <table cellpadding="6">
                            <tr>
                                <td class="tdname">省</td>
                                <td><input type="text" id="sheng" class="textinput" maxlength="50" th:value="${dlxx.getSheng()}"></td>
                            </tr>
                            <tr>
                                <td class="tdname">市/县</td>
                                <td><input type="text" id="shi" class="textinput" maxlength="50" th:value="${dlxx.getShi()}"></td>
                            </tr>
                            <tr>
                                <td class="tdname">地域</td>
                                <td><input type="text" id="diyu" class="textinput" maxlength="50" th:value="${dlxx.getDiyu()}"></td>
                            </tr>

                            <tr>
                                <td class="tdname">流域</td>
                                <td><input type="text" id="liuyu" class="textinput" maxlength="50" th:value="${dlxx.getLiuyu()}"></td>
                            </tr>

                        </table>
                    </td>
                    <td class="righttdtable" width="50%" valign="top"></td>
                </tr>

            </table>

            <div style="margin-left: 80px">
                <input type="button" value="保 &nbsp; &nbsp; 存" class="baocunbtn"  id="Sbutton">
                <input type="button" value="审 &nbsp; &nbsp; 核" class="baocunbtn"  id="Shbutton" shiro:lacksRole="二级审核">
                <span id="Id" th:text="${dlxx.getId()}" class="shownone">Id</span>
                <span id="shenhe" class="shownone" th:text="${dlxx.getShenhe()}"></span>
            </div>

        </td>
    </tr>
</table>


</body>
</html>
<script type="text/javascript">
    // 保存按钮点击事件处理函数
    var saveButton = document.getElementById('Sbutton');
    saveButton.addEventListener('click', ()=> {
        var id=document.getElementById('Id').textContent;
        var shengValue = document.getElementById('sheng').value;
        if(shengValue==""){
            alert("请输入省名！");
            return;
        }
        var shiValue = document.getElementById('shi').value;
        if(shiValue==""){
            alert("请输入市/县名！");
            return;
        }
        var diyuValue = document.getElementById('diyu').value;
        if(diyuValue=="")
            diyuValue=null;
        var liuyuValue = document.getElementById('liuyu').value;
        if(liuyuValue=="")
            liuyuValue=null;
        // 创建要发送的数据对象
        var data = {
            id: id,
            sheng: shengValue,
            shi: shiValue,
            diyu: diyuValue,
            liuyu: liuyuValue
        };
        var xhr = new XMLHttpRequest();
        xhr.open('PUT', '/dlxx/', true);
        xhr.setRequestHeader('Content-Type', 'application/json');
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                // 请求完成并成功处理后的回调函数
                console.log('数据已成功发送至后端');
                alert("保存成功！");
                window.location.href="/dlxx";
            }
        };
        xhr.send(JSON.stringify(data));
    });
    document.getElementById('Shbutton').addEventListener('click', ()=> {
        var id=document.getElementById('Id').textContent;
        var xhr = new XMLHttpRequest();
        xhr.open('PUT', '/dlxx/'+id, true);
        xhr.setRequestHeader('Content-Type', 'application/json');
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                alert("审核成功！");
                window.location.href="/dlxx";
            }
        };
        xhr.send();
    });
    showButton();
    function showButton(){
        let bcBtn = document.getElementById('Sbutton');
        let shBtn = document.getElementById('Shbutton');
        if(document.getElementById('shenhe').innerText=='通过'){
            bcBtn.style.display='none';
            shBtn.style.display='none';
        }
    }
</script>